package controllers;

import models.Photo;
import models.User;
import play.mvc.Before;
import play.mvc.Controller;
import play.mvc.Scope.Session;
import utils.SessionUtils;

public class CheckLogin extends Controller {

	@Before
	public static void checkLogin() throws Throwable {
		if (SessionUtils.getUserId() == null) {
            Application.login();
		} else {
            if(session.get("photoUrl")==null){
                Photo photo = Photo.find("id= ?",SessionUtils.getLoginUser().photoId).first();
                if(photo!=null){
                    session.put("photoUrl",photo.getPhoto());
                }
                else{
                   session.put("photoUrl","../public/images/tt.png");
                }
            }
		}
	}
}
